package com.bajiao.admin.controller.store;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bajiao.common.api.vo.Result;
import com.bajiao.entity.store.StorePermission;
import com.bajiao.service.store.StorePermissionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import com.bajiao.admin.base.AdminBaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 店铺权限
 * @Author: FanJq
 * @Date:   2024-12-24
 * @Version: V1.0
 */
@Slf4j
@Api(tags="店铺权限")
@RestController
@RequestMapping("/store/permission")
public class StorePermissionController extends AdminBaseController<StorePermission, StorePermissionService> {
	@Autowired
	private StorePermissionService storePermissionService;

	/**
	 * @description: 分页列表查询
	 * @author: FanJq
	 * @date:   2024-12-24
	 * @return
	 */
	@ApiOperation(value="店铺权限-分页列表查询", notes="店铺权限-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList() {
		LambdaQueryWrapper<StorePermission> queryWrapper = new LambdaQueryWrapper<>();
        startPage();
        return Result.ok(getDataTable(storePermissionService.list(queryWrapper)));
	}

	 @ApiOperation(value="店铺权限", notes="店铺权限")
	 @GetMapping(value = "/select")
	 public Result<?> getSelect() {
		 List<StorePermission> permissionList = storePermissionService.list();
		 return Result.ok(permissionList);
	 }

	/**
	 * @description: 添加
	 * @author: FanJq
	 * @date:   2024-12-24
	 * @param storePermission
	 * @return
	 */
	@ApiOperation(value="店铺权限-添加", notes="店铺权限-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody StorePermission storePermission) {
		storePermissionService.save(storePermission);
		return Result.ok("添加成功！");
	}

	/**
	 * @description: 编辑
	 * @author: FanJq
	 * @date:   2024-12-24
	 * @param storePermission
	 * @return
	 */
	@ApiOperation(value="店铺权限-编辑", notes="店铺权限-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody StorePermission storePermission) {
		storePermissionService.updateById(storePermission);
		return Result.ok("编辑成功!");
	}

	/**
	 * @description: 通过id删除
	 * @author: FanJq
	 * @date:   2024-12-24
	 * @param id
	 * @return
	 */
	@ApiOperation(value="店铺权限-通过id删除", notes="店铺权限-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		storePermissionService.removeById(id);
		return Result.ok("删除成功!");
	}

	/**
	 * @description: 批量删除
	 * @author: FanJq
	 * @date:   2024-12-24
	 * @param ids
	 * @return
	 */
	@ApiOperation(value="店铺权限-批量删除", notes="店铺权限-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.storePermissionService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.ok("批量删除成功！");
	}

	/**
	 * @description: 通过id查询
	 * @author: FanJq
	 * @date:   2024-12-24
	 * @param id
	 * @return
	 */
	@ApiOperation(value="店铺权限-通过id查询", notes="店铺权限-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		StorePermission storePermission = storePermissionService.getById(id);
		return Result.ok(storePermission);
	}

  /**
   * @description: 导出excel
   * @author: FanJq
   * @date:   2024-12-24
   * @param request
   * @param storePermission
   */
  @RequestMapping(value = "/exportXls")
  public ModelAndView exportXls(HttpServletRequest request, StorePermission storePermission) {
      return super.exportXls(request, storePermission, StorePermission.class, "店铺权限");
  }

  /**
   * @description: 通过excel导入数据
   * @author: FanJq
   * @date:   2024-12-24
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
      return super.importExcel(request, response, StorePermission.class);
  }

}
